﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml.Serialization;
using System.IO;
using Emico.Linq.Criterion;
using System.Runtime.Serialization.Formatters.Binary;

namespace Emico.Core.Tests.Criterion
{
    [TestClass]
    public class LogicalExpressionTest
    {
        [TestMethod]
        public void TestSerialize()
        {
            string propertyName = "Name";
            object value = "Value";

            LtExpression<TestType> lhs = new LtExpression<TestType>(propertyName, value);
            LeExpression<TestType> rhs = new LeExpression<TestType>(propertyName, value);
            AndExpression<TestType> e = new AndExpression<TestType>(lhs, rhs);
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, e);

                ms.Position = 0;
                var result = (AndExpression<TestType>)bf.Deserialize(ms);

                Assert.IsTrue(result.LHS is LtExpression<TestType>);
                Assert.IsTrue(result.RHS is LeExpression<TestType>);
            }
        }
    }
}
